/*
 * @Author: fzs
 * @LastEditors: fzs
 * @Description: 封装http方法，基于fly封装，可以自定义请求拦截
 * @Date: 2019-04-11 10:35:00
 */

import uniFly from 'unifly';
import utils from '../common/utils.js';
import {
  baseApiUrl
} from './env';
import store from '../store';

//基础路由
uniFly.baseUrl = baseApiUrl;
//APICloud签名校验
// let now = Date.now()
// let appId = store.getters.appId
// let appKey = store.getters.appKey
// appKey = utils.SHA1(appId + 'UZ' + appKey + 'UZ' + now) + '.' + now
// //设置请求头
// uniFly.headers['X-APICloud-AppId'] = appId
// uniFly.headers['X-APICloud-AppKey'] = appKey

// 设置token

console.log(store);

let project_token = 18031201;
uniFly.headers['project_token'] = project_token;
//全局请求超时时间
uniFly.timeOut = 20000
//自定义请求拦截
uniFly.requestInterceptors.success = function(request) {
  console.log('自定义请求拦截')
  //配置基本信息
  request.headers = uniFly.headers
  uni.showLoading()
  return request
}
uniFly.responseInterceptors.success = function(request) {
  console.log('自定义响应拦截',request)
  uni.hideLoading()
  return Promise.resolve(request.data)
}


const $request = uniFly;

export default $request